(function (root) {
    !root.app ? root.app = {} : null;

    app.recent = {
        template: "#recent",
        data() {
            return {
                self: this,
                formValidate: {},
                groupList: [],
                appInfo: '',
                deployVo: {
                    systemName: '',
                    appName: '',
                    nickname: '',
                    gitUrl: '',
                    branchName: '',
                    params: '',
                    groupList: [],
                    complieStatusMsg: '',
                    imgStatusMsg: '',
                    deployStatusMsg: '',
                },
                prodGroupView: false,
                color: ['blue', 'green', 'red', 'yellow'],
                isNull: false,
            }
        },
        created() {
            this.loadData();
        },
        methods: {
            doWhile() {
                let timer = setInterval(() => {
                    CommonApi.get("/getDeployInfoById", {id: this.deployVo.id}, data => {
                        this.doFillData(data);
                        if (this.deployVo.deployStatus &&
                            (this.deployVo.complieStatus !== 1 && this.deployVo.imgStatus !== 1 && this.deployVo.deployStatus !== 1)) {
                            clearInterval(timer);
                            console.log("停止");
                        }
                    }, error => {
                        this.$Message.error(error.errors[0].msg);
                    });
                }, 3000);
            },


            //加载数据
            loadData() {
                CommonApi.get("/getDeployInfo", null, data => {
                    this.doFillData(data);
                    this.doWhile();
                }, error => {
                    this.$Message.error(error.errors[0].msg);
                })
            },
            toUpdate() {
                this.$router.push({name: 'content', params: {appName: this.deployVo.appName}});
            },
            toStop() {
                CommonApi.get("/stop", {id: this.deployVo.id}, data => {
                    this.loadData();
                }, error => {
                    this.$Message.error(error.errors[0].msg);
                });
            },
            initStatus: function () {
                if (!this.deployVo.complieStatus) {
                    this.deployVo.complieStatusMsg = {value: 'normal', label: "等待编译", num: 0}
                } else if (this.deployVo.complieStatus === 1) {
                    this.deployVo.complieStatusMsg = {value: 'active', label: "正在编译", num: 50}
                } else if (this.deployVo.complieStatus === 2) {
                    this.deployVo.complieStatusMsg = {value: 'success', label: "编译成功", num: 100}
                } else if (this.deployVo.complieStatus === -1) {
                    this.deployVo.complieStatusMsg = {value: 'wrong', label: "编译失败", num: 100}
                } else if (this.deployVo.complieStatus === 3) {
                    this.deployVo.complieStatusMsg = {value: 'wrong', label: "编译终止", num: 100}
                }
                if (!this.deployVo.imgStatus) {
                    this.deployVo.imgStatusMsg = {value: 'normal', label: "等待构建", num: 0}
                } else if (this.deployVo.imgStatus === 1) {
                    this.deployVo.imgStatusMsg = {value: 'active', label: "正在构建", num: 50}
                } else if (this.deployVo.imgStatus === 2) {
                    this.deployVo.imgStatusMsg = {value: 'success', label: "构建成功", num: 100}
                } else if (this.deployVo.imgStatus === -1) {
                    this.deployVo.imgStatusMsg = {value: 'wrong', label: "构建失败", num: 100}
                } else if (this.deployVo.imgStatus === 3) {
                    this.deployVo.imgStatusMsg = {value: 'wrong', label: "构建终止", num: 100}
                }
                if (!this.deployVo.deployStatus) {
                    this.deployVo.deployStatusMsg = {value: 'normal', label: "等待部署", num: 0}
                } else if (this.deployVo.deployStatus === 1) {
                    this.deployVo.deployStatusMsg = {value: 'active', label: "正在部署", num: 50}
                } else if (this.deployVo.deployStatus === 2) {
                    this.deployVo.deployStatusMsg = {value: 'success', label: "部署成功", num: 100}
                } else if (this.deployVo.deployStatus === -1) {
                    this.deployVo.deployStatusMsg = {value: 'wrong', label: "部署失败", num: 100}
                } else if (this.deployVo.deployStatus === 3) {
                    this.deployVo.deployStatusMsg = {value: 'wrong', label: "部署终止", num: 100}
                }
            },
            doFillData(data) {
                if (!data) {
                    this.isNull = true;
                    return;
                }
                this.deployVo.id = data.id ? data.id : '';
                this.deployVo.systemName = data.systemName ? data.systemName : '';
                this.deployVo.appName = data.appName ? data.appName : '';
                this.deployVo.nickname = data.nickname ? data.nickname : '';
                this.deployVo.gitUrl = data.gitUrl ? data.gitUrl : '';
                this.deployVo.branchName = data.branchName ? data.branchName : '';
                this.deployVo.params = data.params ? data.params : '';
                this.deployVo.rootPom = data.rootPom ? data.rootPom : '';
                this.deployVo.targetPath = data.targetPath ? data.targetPath : '';
                this.deployVo.complieBulidId = data.complieBulidId ? data.complieBulidId : '';
                this.deployVo.imageBulidId = data.imageBulidId ? data.imageBulidId : '';
                this.deployVo.complieStatus = data.complieStatus ? data.complieStatus : '';
                this.deployVo.imgStatus = data.imgStatus ? data.imgStatus : '';
                this.deployVo.deployStatus = data.deployStatus ? data.deployStatus : '';
                this.deployVo.created = data.created ? new Date(data.created).convert('yyyy-MM-dd hh:mm:ss') : '';
                this.deployVo.modified = data.modified ? new Date(data.modified).convert('yyyy-MM-dd hh:mm:ss') : '';
                this.groupList = data.groupList;
                this.groupList.forEach((item, index) => {
                    item.color = this.color[index % 4];
                });
                this.initStatus();
            }

        }
    };
})(window);
